#!usr/bin/env node
import { Event } from './05-event.js';

class Dog extends Event {
  #name;
  #energy;

  constructor(name, energy) {
    super();
    this.#name = name;
    this.#energy = energy;
    this.startBarking();
  }

  startBarking() {
    if (this.#energy > 0) {
      setInterval(() => {
        this.emit('bark', this.#name, this.#energy);
        this.#energy--;
        if (this.#energy <= 0) {
          clearInterval(this.startBarking);
        }
      }, 1000);
    }
  }

  set energy(value) {
    this.#energy = value;
  }

  get energy() {
    return this.#energy;
  }

  get name() {
    return this.#name;
  }
}

export { Dog };